# Contributor: Jacek Pruciak <alpine@juniorjpdj.pl>
# Maintainer: Jacek Pruciak <alpine@juniorjpdj.pl>
pkgname=tcmu-runner
pkgver=1.5.4
pkgrel=1
pkgdesc="A daemon that handles the userspace side of the LIO TCM-User backstore."
url="https://github.com/open-iscsi/tcmu-runner"
arch="all !riscv64" # blocked by ceph
license="Apache-2.0"
makedepends="cmake glib-dev kmod-dev libnl3-dev ceph-dev"
options="!check" # no upstream tests
subpackages="libtcmu:libs libtcmu-dev $pkgname-doc $pkgname-rbd"
source="https://github.com/open-iscsi/tcmu-runner/archive/v$pkgver/tcmu-runner-$pkgver.tar.gz
	tcmu-runner-fix-i586-size_t-error.patch
	time_t-size-fix.patch
	fix-musl-compilation.patch
	"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build \
		-Dwith-glfs=false \
		-Dwith-tcmalloc=false \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		$CMAKE_CROSSOPTS .
	cmake --build build
}

check() {
	# I asked upstream for tests, so let's leave it here. It's disabled anyway.
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

rbd() {
	amove usr/lib/tcmu-runner/handler_rbd.so
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	mkdir -p "$pkgdir"/usr/share/dbus-1/system.d/
	mv "$pkgdir"/etc/dbus-1/system.d/* "$pkgdir"/usr/share/dbus-1/system.d/
}

sha512sums="
e6fad89bd795ca7de38450a94f95fb4f4edb5bca32a34156f5690cf4c236f2f845578f592733a4fba29f64484a909c185b66af87ad92cf3ccff28bf4977ad2c3  tcmu-runner-1.5.4.tar.gz
a26fca68a73e5cc6726e880f5004b96fd0f5d3cbcaf6dd7a6a8a5e03f9089c91ec271b2517ea127b37dcead1499baac7cf6a5f23c0d4a70d13baa0107baefab3  tcmu-runner-fix-i586-size_t-error.patch
8eb7729cc7c89a24f512bb5f206034c8404d96891291fce132d075bd20568f346907185ac70e47d580fc95e9f2112c2695139c66b30e2b37d101988920f21793  time_t-size-fix.patch
2f1e30bbfca685ea05c5481b0e58e3a0bfe15e84652cabe2dabfe081e59313d93ca730754cd6165a848850a782cb273d3ea0976853b3b12a9718b4d3b28a520c  fix-musl-compilation.patch
"
